var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
  data: {
		isload:0,
    st: 0,
    datalist: [],
    pagenum: 1,
		myscore:0,
  },
  _onLoad: function () {
    var that = this;
		wx.setNavigationBarTitle({
			title: (that.data.textset['积分'] ? that.data.textset['积分'] : '积分')+'明细'
		});
    if (that.options.st) {
      that.setData({ st: that.options.st})
    }
		that.setData({ pagenum: 1,st:that.data.st,datalist: [], $nomoreData: false });
		//$.get('my/scorelog',{},function(res){
		//	that.setData(res)
		//})
    that.getDataList();
  },
  changetab: function (e) {
    var st = e.currentTarget.dataset.st
    this.setData({ pagenum: 1, st: st, datalist: [], $nomoreData: false })
    wx.pageScrollTo({
      scrollTop: 0, duration: 0
    })
    this.getDataList()
  },
  getDataList: function () {
    var that = this
    var pagenum = that.data.pagenum
    var st = that.data.st
    $.post('my/scorelog', { st: st, pagenum: pagenum }, function (res) {
      var data = res.data
      if (pagenum == 1) {
        that.setData({ datalist: data,myscore:res.myscore,isload:1});
        if (data.length == 0) {
          $.showEmpty('暂无记录', '/images/empty2.png');
        }
      } else {
        if (data.length == 0) {
          that.setData({ $nomoreData: true });
        } else {
          var datalist = that.data.datalist
          var newdata = datalist.concat(data)
          that.setData({ datalist: newdata });
        }
      }
    });
  },
  onReachBottom: function () {
    if (!this.data.$dataEmpty.visible && !this.data.$nomoreData) {
      this.setData({ pagenum: this.data.pagenum + 1 })
      this.getDataList();
    }
  },
}))